﻿using System;
using System.Collections.Generic;
using System.Text;
using KPIS.GERP.GIMS.MODEL;
using KPIS.DBM;
using System.Data;
using System.Configuration;

namespace KPIS.GERP.GIMS.DAL
{
    public class D_TempCutStock
    {
        DBManager dbManager = new DBManager(DataProvider.MySQL, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public IList<M_TempCutStock> GetList()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_TempCutStock> infoList = new List<M_TempCutStock>();
            try
            {
                dbManager.Open();
                strSQL =  " SELECT icm_receive_seq,quantity,quantity_cut_stock "
                         +" FROM temp_cut_stock ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_TempCutStock info = new M_TempCutStock();
                        info.icm_receive_seq = Convert.ToInt32(drc[i]["icm_receive_seq"]);
                        info.quantity = Convert.ToDouble(drc[i]["quantity"]);
                        info.quantity_cut_stock = Convert.ToDouble(drc[i]["quantity_cut_stock"]);
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }
        public DataTable GetDataTableTemp()
        {
            string strSQL = "";
            DataTable dtb = null;
            try
            {
                dbManager.Open();
                strSQL = " SELECT icm_receive_seq,quantity,quantity_cut_stock "
                       + " FROM temp_cut_stock ";

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        public void Insert_TempCutStock(M_TempCutStock info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);
                dbManager.AddParameters(0, "@icm_receive_seq", info.icm_receive_seq);
                dbManager.AddParameters(1, "@quantity", info.quantity);
                dbManager.AddParameters(2, "@quantity_cut_stock", info.quantity_cut_stock);

                strSQL = " INSERT INTO temp_cut_stock "
                        + " (icm_receive_seq,quantity,quantity_cut_stock) "
                        + " VALUES "
                        + " (@icm_receive_seq,@quantity,@quantity_cut_stock) ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void Delete_TempCutStock()
        {
            string strSQL;
            try
            {
                dbManager.Open();
                strSQL = " DELETE FROM temp_cut_stock ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

    }
}
